package com.chengyu.core.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
import cn.hutool.core.lang.Dict;
import cn.hutool.setting.yaml.YamlUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @title 小程序配置
 * @author LeGreen
 * @date   2021/1/8
 */
@Configuration
public class MPMiniAppConfig {

    @Bean
    public WxMaService customWxMaService(){
        Dict dict = YamlUtil.loadByPath("application.yml");
        String appId = dict.getByPath("mp.miniapp.app-id", String.class);
        String secret = dict.getByPath("mp.miniapp.app-secert", String.class);
        String accessToken = dict.getByPath("mp.miniapp.access-token", String.class);
        String aesKey = dict.getByPath("mp.miniapp.aes-key", String.class);
        WxMaInMemoryConfig config = new WxMaInMemoryConfig();
        config.setAppid(appId);
        config.setSecret(secret);
//        config.setAccessToken(accessToken);
//        config.setAesKey(aesKey);

        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);

        return wxMaService;
    }

}
